﻿using AuroraPlatform.Controls;
using AuroraPlatform.Tools;
using AuroraPlatform.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AuroraPlatform.View
{
    public partial class LightingNavigation : UserControl, IPageProvider
    {
        public LightingNavigation()
        {
            InitializeComponent();

            Pictures.ItemsSource = LightingTypeProvider.LightingTypes;
            Pictures.SelectionChanged += Pictures_SelectionChanged;
        }

        private void Pictures_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (BusinessContext.Singleton.User == null)
                return;

            LightingType lightingType = (LightingType)Pictures.SelectedItem;
            if (lightingType == null)
                return;

            CondProdClass.Builder builder = new CondProdClass.Builder();

            bool hasParameter = false;
            if (lightingType.UsePlace > 0)
            {
                builder.SetUsePlace(lightingType.UsePlace);
                hasParameter = true;
            }

            if (lightingType.Setup > 0)
            {
                builder.SetSetup(lightingType.Setup);
                hasParameter = true;
            }

            if (lightingType.Class > 0)
            {
                builder.SetClass(lightingType.Class);
                hasParameter = true;
            }

            if (hasParameter)
            {
                BusinessContext.Singleton.ParamIterator.GoNew(
                    new NaviTo2Param() 
                    { 
                        Parameter = builder.Build(),
                        //SourceUrl = MainPage.PortalUri
                        CurrentUrl = MainPage.Level2Uri
                    });
                Navigation.Navigate(new Uri(MainPage.Level2Uri, UriKind.RelativeOrAbsolute));
            }
            else
            {
                if (lightingType.Alias == "SearchNewProds")
                {
                    BusinessContext.Singleton.ParamIterator.GoNew(
                        new NaviTo1MonthParam()
                        {
                            CurrentUrl = MainPage.Level3Uri
                        });
                    Navigation.Navigate(new Uri(MainPage.Level3Uri, UriKind.RelativeOrAbsolute));
                }
            }
        }

        public PageLevel PageLevel
        {
            get { return PageLevel.First; }
        }


        public INavigate Navigation
        {
            get;
            set;
        }
    }
}
